var baxiaCommon = function () {
    "use strict";
    var e = function (e, t) {
        return !!e && e.indexOf(t) > -1
    }, t = function (e) {
        for (var t = Array(e.length), n = 0; t.length > n; ++n) t[n] = e[n];
        return t
    }, n = function (e, t, n) {
        return e.indexOf("?") > -1 ? e + "&" + t + "=" + n : e + "?" + t + "=" + n
    }, r = function (e, t, n) {
        return e + "&" + t + "=" + n
    };

    function a(t) {
        return t && !e(t, "_bx-v") ? n(t, "_bx-v", i) : t
    }

    var i = "1.1.20", o = location, s = document, u = function (e, t, n) {
        (void 0 === t && (t = 1), void 0 === n && (n = 1), 0 >= n || Math.random() < n) && function (e, t) {
            var n = [];
            for (var r in e) n.push(r + "=" + encodeURIComponent(e[r]));
            (new Image).src = t + n.join("&")
        }({
            code: t,
            msg: (e + "").substr(0, 1e3) + ";v:" + i,
            pid: "baxia",
            page: o.href.split(/[#?]/)[0],
            query: o.search.substr(1),
            hash: o.hash,
            referrer: s.referrer,
            title: s.title,
            ua: navigator.userAgent
        }, "//gm.mmstat.com/fsp.1.1?")
    };

    function c(e) {
        u(e, 13, 1)
    }

    var f = window, d = function (e, t) {
        var n = f.__baxia__ || {};
        return e ? n[e] || t : n
    }, p = function (e, t) {
        f.__baxia__ = f.__baxia__ || {}, f.__baxia__[e] = t
    }, l = function (e, t, n, r) {
        if (void 0 === r && (r = !1), t.addEventListener) t.addEventListener(e, n, r); else if (t.attachEvent) return t.attachEvent("on" + e, n), !1
    }, h = function () {
        var e = {test: "true"};
        try {
            return Object.defineProperty(e, "test", {
                enumerable: !1,
                value: e
            }), Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, "readyState") && e.test == e.test
        } catch (t) {
            return !1
        }
    }(), v = function (e, n, r, a) {
        var i = e[n];
        e[n] = function () {
            var e = t(arguments);
            if (r && !a && !1 === r.apply(this, e)) return;
            return a && (e = r.apply(this, e)), i.apply(this, e)
        }
    }, y = function (e, n, r) {
        var a = e[n];
        e[n] = function () {
            var e = t(arguments);
            if (r && !1 === r.apply(this, e)) return;
            return a.apply(this, e)
        }
    }, m = function (t) {
        void 0 === t && (t = "");
        var n = {valid: !1, type: ""};
        if ("object" == typeof t) t = JSON.stringify(t); else try {
            JSON.parse(t)
        } catch (i) {
            return n.valid = !0, n
        }
        t = t.toLocaleLowerCase();
        var r = e(t, "rgv587_"), a = !r && e(t, "assist_flag") && e(t, "url");
        return r || a ? n : (n.valid = !0, n)
    }, g = XMLHttpRequest.prototype, b = null, w = function (e) {
        var n, r, i, o, s = e.done;
        try {
            h && function (e, n, r, a) {
                if (Object.getOwnPropertyDescriptor) {
                    var i = Object.getOwnPropertyDescriptor(e, n);
                    if (h && !i || !i) c("错误：不支持 hookProperty"); else {
                        var o = i.set, s = i.get;
                        h && Object.defineProperty(e, n, {
                            set: function () {
                                var e = t(arguments);
                                if (r) {
                                    var n = r && r.apply(this, e);
                                    e = n ? [n] : e
                                }
                                o && o.apply(this, e)
                            }, get: function () {
                                var e = s && s.apply(this);
                                return a ? a.call(this, e) : e
                            }
                        })
                    }
                }
            }(g, "readyState", null, function (e) {
                var t = e, n = this;
                this._onreadystatechange = this._onreadystatechange || this.onreadystatechange;
                var r = x(n);
                if (3 !== t || m(r).valid) {
                    if (4 === t && "json" === n.responseType && !m(r).valid) return void s({
                        response: r,
                        readyState: t,
                        xhr: this,
                        eventKey: "onreadystatechange"
                    })
                } else this.onreadystatechange = function (e) {
                    var a = this;
                    b = window.event || e || b, r = x(n), s({
                        response: r,
                        readyState: t,
                        xhr: n,
                        eventKey: "onreadystatechange",
                        event: b
                    }, function () {
                        a._onreadystatechange(b)
                    })
                };
                return t
            })
        } catch (u) {
            c("hook xhr ,message:" + u.message)
        }
        y(g, "send", function () {
            var e = this;
            this.sendParams = arguments, this._onload || (this._onload = this.onload), this.onload && (this.onload = function (e) {
                var t = this;
                b = window.event || e;
                var n = x(this);
                s({response: n, readyState: 3, xhr: this, eventKey: "onload"}, function () {
                    t._onload && t._onload(b)
                })
            }), !h && l("readystatechange", this, function () {
                var t = x(e);
                s({response: t, readyState: e.readyState, xhr: e, eventKey: "readystatechange"})
            })
        }), g.addEventListener && (i = function () {
            var e = t(arguments), n = e[1];
            return e[1] = function (e) {
                var r = e.type, a = t(arguments);
                if ("load" === r || "readystatechange" === r) {
                    var i = x(e.target);
                    if (i) {
                        var o = this;
                        return void s({response: i, readyState: 3, xhr: o, eventKey: r}, function () {
                            n.apply(o, a)
                        })
                    }
                }
                n.apply(this, t(arguments))
            }, e
        }, o = (n = g)[r = "addEventListener"], n[r] = function () {
            var e = t(arguments), n = i.apply(void 0, e);
            return o.apply(this, n)
        }), y(g, "setRequestHeader", function (e, t) {
            this._header_ = this._header_ || {}, this._header_[e] = t
        }), v(g, "open", function () {
            this.openParams = arguments;
            var e = t(arguments);
            return e[1] = a(e[1]), e
        }, !0)
    };

    function x(e) {
        var t = "";
        try {
            t = e.response || e.responseText
        } catch (n) {
            t = ""
        }
        return t
    }

    var O, S = document, k = function (e, t, n) {
        if (!e) return t();
        var r = S.getElementsByTagName("script")[0], a = S.createElement("script");
        if (a.async = !0, a.src = e, e.indexOf("alicdn") > -1 && (a.crossOrigin = !0), a.onerror = function (t) {
            u("function:loadJS. msg:" + e + "load error。props：" + JSON.stringify(n)), a.onerror = null
        }, t) {
            var i = !1;
            a.onload = a.onreadystatechange = function () {
                i || a.readyState && !/loaded|complete/.test(a.readyState) || (a.onload = a.onreadystatechange = null, i = !0, t())
            }
        }
        r.parentNode.insertBefore(a, r)
    }, _ = [], N = function (e, t) {
        void 0 === e && (e = "Xhr"), void 0 === t && (t = {});
        try {
            if (O) return O.destroy(), O.handler(t);
            _.push({pluginName: e, props: t});
            var n = _[0], r = "baxia" + n.pluginName + "Handler", a = function (e, t) {
                return t && t.result && t.result.jsPath ? t.result.jsPath : "" + d("cdnPath", "https://g.alicdn.com/sd/baxia/" + i + "/") + e + ".js"
            }(r, n.props);
            k(a, function () {
                if (!O) {
                    O = new window[r];
                    for (var e = 0; _.length > e; e++) O.handler(_[e].props);
                    _ = []
                }
            })
        } catch (o) {
            O = null, u("handler err，param:" + e + JSON.stringify(t) + "," + o.message + o.stack)
        }
    };
    var F = {
        version: i, init: function () {
            try {
                w({
                    done: function (e, t) {
                        var n = e.response, r = e.readyState, a = e.xhr, i = e.eventKey;
                        n || (n = function (e) {
                            var t = "";
                            try {
                                t = e.response || e.responseText
                            } catch (n) {
                                t = ""
                            }
                            return t
                        }(a)), a._processing || (a._processing || 3 > r || m(n).valid ? t && t() : (a._processing = !0, "onreadystatechange" === i && (a.onload = a._onload), N("Xhr", {
                            result: n,
                            config: {
                                xhr: a, url: a.responseURL, fail: function () {
                                    var e = a.onerror || a.onabort || a.ontimeout || t;
                                    e && e()
                                }
                            }
                        })))
                    }
                })
            } catch (e) {
                c("hook xhr,m:" + e.message)
            }
        }
    };
    var P = function (e) {
        var t = e.done, n = window.fetch;
        n && (window.fetch = function () {
            var e = arguments;
            return new window.Promise(function (r, i) {
                var o = e[1] || {};
                o.credentials && "omit" !== o.credentials || (o.credentials = "same-origin"), e[0] = a(e[0]), n.apply(window, e).then(function (n) {
                    try {
                        var a = n.headers.get("content-type");
                        if (-1 >= a.indexOf("json") && -1 >= a.indexOf("text")) return r(n)
                    } catch (s) {
                        return r(n)
                    }
                    n.clone().text().then(function (a) {
                        return t ? t({
                            parentConfig: o,
                            parentArguments: e,
                            response: n,
                            data: a,
                            resolve: r,
                            reject: i
                        }) : (r(n), a)
                    })
                })["catch"](function (e) {
                    i(e)
                })
            })
        })
    };
    var H = {
        init: function () {
            try {
                P({
                    done: function (e) {
                        var t, n = e.parentArguments, r = e.response, a = e.data, i = e.resolve, o = e.reject,
                            s = a.config || {};
                        return s && ((s = e.parentConfig).url = n[0].url || n[0]), m(a).valid ? ((t = s.baxiaData && s.baxiaData.defer) ? t.resolve(r) : i(r), a) : (s.baxiaData = {
                            defer: t = {
                                resolve: i,
                                reject: o
                            }, response: r
                        }, N("Fetch", {result: a, config: s}), t.promise)
                    }
                })
            } catch (e) {
                c("Hook Fetch ，Message:" + e.message)
            }
        }
    }, C = function (e) {
        if (!e || "string" != typeof e) return !1;
        var t = d("options", {}).checkApiPath;
        return !(!t || !t(e))
    };
    var E, j = {}, A = d("events", {}), D = {
        on: function (e, t) {
            return (A[e] || (A[e] = [])).push(t), p("events", A), j
        }, once: function (e, n) {
            var r = this, a = function () {
                n.apply(r, t(arguments)), r.off(e, a)
            };
            return this.on(e, a), j
        }, off: function (e, t) {
            if (!e && !t) return A = {}, j;
            var n = A[e];
            if (n) if (t) for (var r = n.length - 1; r >= 0; r--) n[r] === t && n.splice(r, 1); else delete A[e];
            return j
        }, fire: function (e, t) {
            var n = (A = d("events", {}))[e];
            if (n) for (var r = 0, a = (n = n.slice()).length; a > r; r++) n[r](t);
            return j
        }
    }, T = "event:awscReady@baxia";
    !function (e) {
        e[e.Null = 0] = "Null", e[e.QueryString = 1] = "QueryString", e[e.JSONString = 2] = "JSONString", e[e.FormData = 3] = "FormData", e[e.FormUrlEncoded = 4] = "FormUrlEncoded", e[e.Form = 5] = "Form", e[e.XHRHeader = 6] = "XHRHeader", e[e.FetchHeader = 7] = "FetchHeader"
    }(E || (E = {}));
    var q = function (e) {
        if (!e) return e;
        var t = d("options", {}).asac;
        return t ? e = K(L(e), e, [{key: "bx-asac", value: t}]) : e
    }, J = function (e) {
        try {
            var t = window.fyOBJ, n = t.getUA(), r = t.umidToken, a = R(e),
                i = [{key: "bx-ua", value: n}, {key: "bx-umidtoken", value: r}], o = d("ncData");
            o && o.length > 0 && (i = i.concat(o)), e = K(a, e, i)
        } catch (s) {
            u("addParamToRequest:" + s.message)
        }
        return e
    }, R = function (e) {
        var t = U(e);
        if (t) return t;
        var n = e.params;
        return !function (e) {
            var t = !0;
            try {
                JSON.parse(e)
            } catch (n) {
                t = !1
            }
            return t
        }(n) ? n instanceof FormData ? t = E.FormData : "string" == typeof n && n.indexOf("=") > -1 ? t = E.FormUrlEncoded : n instanceof HTMLFormElement && (t = E.Form) : t = E.JSONString, t
    }, L = function (e) {
        return U(e) || E.QueryString
    }, U = function (e) {
        var t = null;
        return "header" === d("options", {}).appendTo && (e.request instanceof XMLHttpRequest ? t = E.XHRHeader : e.request && "object" == typeof e.request && (t = E.FetchHeader)), t
    };

    function X(e) {
        var t = d("options", {}), n = t.asac, r = t.awscTimeout;
        if (D.once(T, function () {
            var t, r, a, i;
            (e.isAppend() || (n && (e = q(e)), e = J(e)), t = d() || {}, i = t.ncData, !(a = void 0 === (r = t.options) ? {} : r).renderNC || i && 0 !== i.length || ((a.unVerifiedCallback || function () {
                alert("请先完成验证后再进行操作")
            })(), 0)) ? e.process(e) : e.canNotSubmit && e.canNotSubmit()
        }), !window.fyOBJ) return setTimeout(function () {
            D.fire(T)
        }, r || 3e3), e;
        D.fire(T)
    }

    function K(e, t, a) {
        switch (e) {
            case E.XHRHeader:
                M(t.params, a, function (e) {
                    t.request.setRequestHeader(e.key, e.value)
                });
                break;
            case E.FetchHeader:
                var i = t.headers || {};
                M(t.params, a, function (e) {
                    i[e.key] = e.value
                }), t.headers = i;
                break;
            case E.Form:
                M(t.params, a, function (e) {
                    !function (e, t, n) {
                        var r = document.createElement("input");
                        r.type = "hidden", r.name = t, r.value = n, e.appendChild(r)
                    }(t.params, e.key, e.value)
                });
                break;
            case E.QueryString:
                M(t.params, a, function (e) {
                    t.url = n(t.url, e.key, e.value)
                });
                break;
            case E.FormUrlEncoded:
                M(t.params, a, function (e) {
                    t.params = r(t.params, e.key, e.value)
                });
                break;
            case E.FormData:
                M(t.params, a, function (e) {
                    t.params.append(e.key, e.value)
                });
                break;
            case E.JSONString:
                var o = t.params ? JSON.parse(t.params) : {};
                M(o, a, function (e) {
                    o[e.key] = e.value
                }), t.params = JSON.stringify(o)
        }
        return t
    }

    function M(e, t, n) {
        for (var r = t.length, a = 0; r > a; a++) n(t[a]);
        return e
    }

    var I = XMLHttpRequest.prototype, B = function () {
        try {
            r = function (e, t) {
                var n = this;
                if (!this.effectUrl) return t.apply(this, e);
                X({
                    url: this.effectUrl, request: this, params: e[0], headers: null, isAppend: function () {
                        return n.appended
                    }, process: function (e) {
                        t.call(n, e.params)
                    }
                })
            }, a = (e = I)[n = "send"], e[n] = function () {
                var e = t(arguments);
                r.call(this, e, a)
            }, v(I, "open", function () {
                var e = t(arguments), n = e[1];
                return !C(n) || this.effectUrl ? (this.appended = !0, e) : (this.effectUrl = e[1], "header" === d("options", {}).appendTo ? e : (n = q({
                    url: n,
                    request: null,
                    params: null,
                    headers: null
                }).url, e[1] = n, e))
            }, !0)
        } catch (i) {
            c("xhr token" + i.message)
        }
        var e, n, r, a
    }, Q = function (e) {
        var t = "", n = navigator.userAgent.match(/.*(iPhone|iPad|Android|ios|SymbianOS|Windows Phone).*/i);
        n ? (t = "register_h5", k("//g.alicdn.com/sd/nch5/index.js", function () {
            var e = window.NoCaptcha;
            e.init(i), e.setEnabled(!0)
        })) : (t = "register", k("//g.alicdn.com/sd/ncpc/nc.js", function () {
            window.noCaptcha(i)
        }));
        var r = e.verifiedCallback, a = e.showCallback, i = {
            renderTo: "#" + e.renderTo.id,
            appkey: "NCAPPKEY",
            token: "NCTOKENSTR",
            scene: t,
            replaceCallback: function (e, t, a) {
                var i, o = [];
                n ? i = a.bind(this, "ok") : (i = e.success, t = e.data);
                var s = JSON.parse(t.p);
                o.push({key: "bx-nc-ua", value: t.n}), o.push({
                    key: "bx-nc-umidtoken",
                    value: s && s.umidToken
                }), p("ncData", o), r && r(), i({success: !0, result: {code: 0}})
            },
            language: e.ncLanguage
        };
        a && a()
    }, W = function () {
        var e = d("options", {});
        e.renderNC = e.renderNC || location.search.indexOf("renderNC") > -1, e.renderNC && Q(e), function (e) {
            var t = window.AWSC;
            e.umOptions = e.umOptions || {}, e.umOptions.appName = e.umOptions.appName || "security-fourier", e.uabOptions = e.uabOptions || {}, e.uabOptions.Flag = e.uabOptions.Flag || 2980046, t && t.configFY(function (e) {
                window.fyOBJ = e, D.fire("event:awscReady@baxia")
            }, e.umOptions, e.uabOptions)
        }(e), function () {
            try {
                var e = window.fetch;
                if (!e) return;
                window.fetch = function () {
                    var t = arguments;
                    return new window.Promise(function (n, r) {
                        var a = t[0], i = t[1] || {}, o = function () {
                            e.apply(window, t).then(function (e) {
                                return n(e)
                            })["catch"](function (e) {
                                r(e)
                            })
                        };
                        if ("string" != typeof a) return o();
                        if (!C(a)) return o();
                        var s = i.headers, u = i.body, c = void 0 === u ? "{}" : u;
                        X({
                            url: a, params: c, headers: s, request: {}, isAppend: function () {
                                return s && s["bx-ua"] || c && c.indexOf("bx-ua") > -1
                            }, process: function (e) {
                                var n = e.headers, r = e.params;
                                t[0] = e.url, function (e) {
                                    if (!e) return !0;
                                    for (var t in e) return !1;
                                    return !0
                                }(n) || (i.headers = n), r && "{}" !== r && (i.body = r), t[1] = i, o()
                            }
                        })
                    })
                }
            } catch (t) {
                c("fetch token" + t.message)
            }
        }(), B(), function () {
            try {
                var e = !1, t = function (t) {
                    if ("submit" === t.type) {
                        var n = t.target || t.srcElement, r = n.getAttribute("action") || location.href;
                        if (!C(r)) return;
                        if (!0 === e) return void t.preventDefault();
                        e = t.formSubmit, X({
                            url: r, params: n, headers: {}, request: {}, isAppend: function () {
                                return !!n["bx-ua"]
                            }, canNotSubmit: function () {
                                t.preventDefault()
                            }, process: function (e) {
                                var t = e.url;
                                r !== t && n.setAttribute("action", t)
                            }
                        })
                    }
                };
                l("submit", document, t);
                var n = window.HTMLFormElement;
                n && y(n.prototype, "submit", function () {
                    e = !1, t({
                        type: "submit", target: this, formSubmit: !0, preventDefault: function () {
                            throw"未完成验证"
                        }
                    })
                })
            } catch (r) {
                c("form token" + r.message)
            }
        }()
    };
    d("baxiaPromptInit") || (p("baxiaPromptInit", !0), F.init(), H.init());
    var Y = {
        set: p, version: i, init: function (e) {
            void 0 === e && (e = {}), p("options", e), d("baxiaInit") || (p("baxiaInit", !0), e.checkApiPath && W())
        }
    };
    return u("i,c", 11, .01), Y
}();
